/* ----------------------------------------------------------------------------
* File: base_module.h
*
* Desc: Base module for Skype plugin
*
* Created: 29/06/2011, by Alexey Korshunov
* ---------------------------------------------------------------------------- */
#ifndef _BASE_MODULE_H_
#define _BASE_MODULE_H_

#include <string>
#include <memory>
#include "exception.h"
#include "logger.h"
#include "thread_wrapper.h"

namespace ModuleManagement
{
	enum ModuleType
	{
		MODULE_TYPE_UNKNOWN = 0,
		MODULE_TYPE_QUIZ,
		MODULE_TYPE_WEATHER,
		MODULE_TYPE_TALK
	};

	class BaseModule 
		: protected Common::ThreadWrapper
	{
	public:
		BaseModule(const std::string& name, const ModuleType& type)
			throw(Common::Exception);
		virtual ~BaseModule();

		virtual Common::Error Start();
		virtual Common::Error Stop();
		virtual Common::Error WaitStop();

		ModuleType GetType() const;
		size_t GetID() const;
		void SetID(size_t id);

	protected:
		virtual Common::Error RunLogic() = 0;
		virtual Common::Error BeforeRun() = 0;
		virtual Common::Error AfterRun() = 0;

	private:
		virtual Common::Error Run();
		std::auto_ptr<Common::Logger> m_Logger;
		std::string Name;
		ModuleType Type;
		size_t ID;
	};
}

#endif // _BASE_MODULE_H_